<?php
namespace jy_zushou;
defined('BY_JYA') or exit('error');
/*
	任务
*/
class task extends \plugin{
    public function xingyong_kou_fee($orderid=0){
		$params=array('status'=>22,'ispay'=>1,'uniacid'=>$_SESSION['uniacid'],'plugin_name'=>'jy_zushou');
		if($orderid){
			$params['id']=$orderid;
		}
		$noexi=$orderid?0:1;
		$orders=pdo_getall('jy_weishop_order',$params);
		$iskou=0;
        foreach($orders as $order){
			$order['api_data']=json_decode($order['api_data'],true);
			$allqi=$order['api_data']['allqi'];
			$zudan=array();
			$starttime=strtotime($order['api_data']['starttime']);
			for($i=1;$i<=$allqi;$i++){
				$day=$starttime+30*($i-1)*24*3600;
				$day=date('Y-m-d',$day);
				$log=$this->pdo_get('log',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$order['id'],'qinum'=>$i));
				$ispay=$log['ispay'];
				if(!$ispay){
					$this->model('model')->xinyong_pay($log['id'],$order['id'],$i,$noexi);
					$iskou=1;
				}
			}
        }
		if(!$noexi && !$iskou){
			exi('没有可扣款的项目','error');
		}
        return true;
    }
}